Force usage of common "GPSBabel file api" (gbfile).
authoroliskoli <oliskoli>
Sat, 2 Dec 2006 20:55:12 +0000 (20:55 +0000)
committeroliskoli <oliskoli>
Sat, 2 Dec 2006 20:55:12 +0000 (20:55 +0000)
axim_gpb.c
geo.c
holux.c
hsa_ndv.c
psitrex.c
vcf.c

index 398fe378886e410e96f7e60c356894a553385ff4..d7e70da6f45fd8f5121fdea3d82849cd7cb4bab5 100644 (file)
@@ -29,7 +29,7 @@
 
 #define RECORD_LEN     344
 
-static FILE *fin;
+static gbfile *fin;
 
 static
 arglist_t axim_gpb_args[] = {
@@ -124,13 +124,13 @@ decode_buff(const char *buff, route_head *track)
 static void
 axim_gpb_rd_init(const char *fname)
 {
-       fin = xfopen(fname, "rb", MYNAME);
+       fin = gbfopen(fname, "rb", MYNAME);
 }
 
 static void 
 axim_gpb_rd_deinit(void)
 {
-       fclose(fin);
+       gbfclose(fin);
 }
 
 static void
@@ -139,18 +139,10 @@ axim_gpb_read(void)
        char buff[RECORD_LEN];
        route_head *track = NULL;
        size_t bytes;
-       long filesize, left;
 
-       fseek(fin, 0, SEEK_END);
-       filesize = ftell(fin);
-
-       left = filesize - ((filesize / RECORD_LEN) * RECORD_LEN);
-       is_fatal((left != 0), MYNAME ": Invalid or unsupported file (filesize).");
-       
-       fseek(fin, 0, SEEK_SET);        /* seek file to start */
-       
-       while ((bytes = fread(buff, 1, RECORD_LEN, fin)))
+       while ((bytes = gbfread(buff, 1, RECORD_LEN, fin)))
        {
+               is_fatal((bytes != RECORD_LEN), MYNAME ": Invalid or unsupported file (filesize).");
                if (track == NULL)
                {
                        track = route_head_alloc();
diff --git a/geo.c b/geo.c
index 96f9d8d7b8ddb97afb243876b93568ee7f6b1522..c19706a96cbe99761b27bd5364e7d84ede658acd 100644 (file)
--- a/geo.c
+++ b/geo.c
@@ -24,7 +24,7 @@ static char *nuke_placer;
 
 static waypoint *wpt_tmp;
 
-static FILE *ofd;
+static gbfile *ofd;
 
 static
 arglist_t geo_args[] = {
@@ -164,13 +164,13 @@ geo_rd_deinit(void)
 static void
 geo_wr_init(const char *fname)
 {
-       ofd = xfopen(fname, "w", MYNAME);
+       ofd = gbfopen(fname, "w", MYNAME);
 }
 
 static void
 geo_wr_deinit(void)
 {
-       fclose(ofd);
+       gbfclose(ofd);
 }
 
 static void
@@ -178,34 +178,34 @@ geo_waypt_pr(const waypoint *waypointp)
 {
        char *tmp;
 
-       fprintf(ofd, "<waypoint>\n");
-       fprintf(ofd, "<name id=\"%s\">", waypointp->shortname);
-       fprintf(ofd, "<![CDATA[%s]]>", waypointp->description);
-       fprintf(ofd, "</name>\n");
+       gbfprintf(ofd, "<waypoint>\n");
+       gbfprintf(ofd, "<name id=\"%s\">", waypointp->shortname);
+       gbfprintf(ofd, "<![CDATA[%s]]>", waypointp->description);
+       gbfprintf(ofd, "</name>\n");
 
-       fprintf(ofd, "<coord lat=\"%lf\" lon=\"%lf\"/>",
+       gbfprintf(ofd, "<coord lat=\"%lf\" lon=\"%lf\"/>",
                waypointp->latitude,
                waypointp->longitude);
-       fprintf(ofd, "\n");
+       gbfprintf(ofd, "\n");
 
        if (waypointp->icon_descr) {
-               fprintf(ofd, "<type>%s</type>\n", deficon ? deficon : waypointp->icon_descr);
+               gbfprintf(ofd, "<type>%s</type>\n", deficon ? deficon : waypointp->icon_descr);
        }
        if (waypointp->url) {
                tmp = xml_entitize(waypointp->url);
-               fprintf(ofd, "<link text =\"Cache Details\">%s</link>\n", 
+               gbfprintf(ofd, "<link text =\"Cache Details\">%s</link>\n", 
                        tmp);
                xfree(tmp);
        }
-       fprintf(ofd, "</waypoint>\n");
+       gbfprintf(ofd, "</waypoint>\n");
 }
 
 static void
 geo_write(void)
 {
-       fprintf(ofd, "<?xml version=\"1.0\"?><loc version=\"1.0\" src=\"EasyGPS\">\n");
+       gbfprintf(ofd, "<?xml version=\"1.0\"?><loc version=\"1.0\" src=\"EasyGPS\">\n");
        waypt_disp_all(geo_waypt_pr);
-       fprintf(ofd, "</loc>\n");
+       gbfprintf(ofd, "</loc>\n");
 }
 
 ff_vecs_t geo_vecs = {
diff --git a/holux.c b/holux.c
index df475d6c95d13c447d819c677126b74625299301..a3ffe6baa3a4e13a0ceb645182447ab6027fcca1 100644 (file)
--- a/holux.c
+++ b/holux.c
@@ -32,7 +32,7 @@ History:
 #include "holux.h"
 
 
-static  FILE *file_in;
+static  gbfile *file_in;
 static         unsigned char *HxWFile;
 static  short_handle mkshort_handle;
 static  char fOutname[256];
@@ -41,13 +41,13 @@ static  char fOutname[256];
 
 static void rd_init(const char *fname)
 {
-       file_in = xfopen(fname, "rb", MYNAME);
+       file_in = gbfopen_le(fname, "rb", MYNAME);
 }
 
 
 static void rd_deinit(void)
 {
-       fclose(file_in);
+       gbfclose(file_in);
 }
 
 
@@ -95,7 +95,7 @@ static void data_read(void)
     HxWpt = xcalloc(GM100_WPO_FILE_SIZE, 1);
 
     /* read the wpo file to the data-array */
-    iDataRead = fread( HxWpt, 1, GM100_WPO_FILE_SIZE, file_in );
+    iDataRead = gbfread( HxWpt, 1, GM100_WPO_FILE_SIZE, file_in );
 
     if (iDataRead == 0)
     {
index 23bb305a2ee88cec4275fa025f04cfd6118046d6..527bcba635c134885b9bcbde7b6115bd826fd6ef 100644 (file)
--- a/hsa_ndv.c
+++ b/hsa_ndv.c
@@ -36,10 +36,10 @@ static char *routeName = "ROUTENAME";
 #define ATTR_OBJECTNAME                                                "OBJNAM"
 #define ATTR_SHIPNAME                                          "shpnam"
 
-static void readVersion4( FILE* pFile);
+static void readVersion4(gbfile* pFile);
 static void getAttr(const char *data, const char *attr, char **val, char seperator);
 
-static FILE *fd;
+static gbfile *fd;
 static gbfile *ofd;
 
 static
@@ -209,7 +209,7 @@ hsa_ndv_cdata(void *dta, const XML_Char *s, int len)
 static void
 hsa_ndv_rd_init(const char *fname)
 {
-       fd = xfopen(fname, "r", MYNAME);
+       fd = gbfopen(fname, "r", MYNAME);
 
        psr = XML_ParserCreate(NULL);
        if (!psr) {
@@ -228,14 +228,14 @@ hsa_ndv_read(void)
        int len;
        char buf[MY_CBUF + 1];
        
-       while ((len = fread(buf, 1, sizeof(buf) - 1, fd))) 
+       while ((len = gbfread(buf, 1, sizeof(buf) - 1, fd))) 
        {
                char *bad;
 
                buf[len] = '\0';
                if (NULL != strstr(buf, "nver=1"))
                {//its the older format, not xml
-                       fseek(fd, 0, SEEK_SET);
+                       gbfseek(fd, 0, SEEK_SET);
                        readVersion4(fd);
                        break;
                }
@@ -245,7 +245,7 @@ hsa_ndv_read(void)
                {
                        *bad = REPLACEMENT_SIRIUS_ATTR_SEPARATOR;
                }
-               if (!XML_Parse(psr, buf, len, feof(fd))) {
+               if (!XML_Parse(psr, buf, len, gbfeof(fd))) {
                        fatal(MYNAME ":Parse error at %d: %s\n", 
                                (int) XML_GetCurrentLineNumber(psr),
                                XML_ErrorString(XML_GetErrorCode(psr)));
@@ -289,7 +289,7 @@ hsa_ndv_rd_deinit(void)
        if ( cdatastr ) {
                xfree(cdatastr);
        }
-       fclose(fd);
+       gbfclose(fd);
 }
 
 static void
@@ -379,10 +379,10 @@ ff_vecs_t HsaEndeavourNavigator_vecs = {
 #define INVALID_TIME -1L
 #define SOUNDARRAY_CHAR 'S'
 
-static int readRecord( FILE* pFile, const char* pRecName, char *recData);
-static int readPositionRecord( FILE* pFile, double* lat, double* lng, long* timeStamp);
+static int readRecord(gbfile* pFile, const char* pRecName, char *recData);
+static int readPositionRecord(gbfile* pFile, double* lat, double* lng, long* timeStamp);
 
-static void readVersion4( FILE* pFile)
+static void readVersion4(gbfile* pFile)
 {
        while( TRUE )
        {
@@ -476,12 +476,12 @@ static void readVersion4( FILE* pFile)
                waypt_add(wpt_tmp);
        }
 
-       fclose(pFile);
+       gbfclose(pFile);
        return;
 }
 
 // read a record to a file
-static int readRecord( FILE* pFile, const char* pRecName, char *recData)
+static int readRecord(gbfile* pFile, const char* pRecName, char *recData)
 {
        // get the rec name
        int len;
@@ -490,7 +490,7 @@ static int readRecord( FILE* pFile, const char* pRecName, char *recData)
 
        for( len = 0; len < ED_REC_NAME_SIZE; len++)
        {
-               int c = fgetc( pFile);
+               int c = gbfgetc(pFile);
 
                // if we hit EOF failed
                if( c == EOF )
@@ -506,7 +506,7 @@ static int readRecord( FILE* pFile, const char* pRecName, char *recData)
        // get the rec data
        for( len = 0; TRUE; len++)
        {
-               int c = fgetc( pFile);
+               int c = gbfgetc( pFile);
 
                // if we hit EOF failed
                if( c == EOF )
@@ -526,7 +526,7 @@ static int readRecord( FILE* pFile, const char* pRecName, char *recData)
 }
 
 // read position
-static int readPositionRecord( FILE* pFile, double* lat, double* lng, 
+static int readPositionRecord(gbfile* pFile, double* lat, double* lng, 
                                                long* timeStamp)
 {
        // read the lat record
index d0d6c7187083deeb6dc37205c378121b17fc72ad..e2aa4fb1700a8067b86912fee402628ddb8372b0 100755 (executable)
--- a/psitrex.c
+++ b/psitrex.c
@@ -41,8 +41,8 @@ typedef struct psit_icon_mapping {
        const char      *icon;
 } psit_icon_mapping_t;
 
-static FILE *psit_file_in;
-static FILE *psit_file_out;
+static gbfile *psit_file_in;
+static gbfile *psit_file_out;
 static short_handle mkshort_handle;
 
 /* 2 = not written any tracks out
@@ -180,25 +180,25 @@ psit_find_icon_number_from_desc(const char *desc)
 static void
 psit_rd_init(const char *fname)
 {
-       psit_file_in = xfopen(fname, "r", MYNAME);
+       psit_file_in = gbfopen(fname, "r", MYNAME);
 }
 
 static void
 psit_rd_deinit(void)
 {
-       fclose(psit_file_in);
+       gbfclose(psit_file_in);
 }
 
 static void
 psit_wr_init(const char *fname)
 {
-       psit_file_out = xfopen(fname, "w", MYNAME);
+       psit_file_out = gbfopen(fname, "w", MYNAME);
 }
 
 static void
 psit_wr_deinit(void)
 {
-       fclose(psit_file_out);
+       gbfclose(psit_file_out);
 }
 
 /*
@@ -206,26 +206,26 @@ psit_wr_deinit(void)
  * and write into buf.
  */
 static void
-psit_getToken(FILE *psit_file, char *buf, size_t sz, psit_tokenSep_type delimType)
+psit_getToken(gbfile *psit_file, char *buf, size_t sz, psit_tokenSep_type delimType)
 {
        int c = -1;
 
        *buf = 0;
 
        if (delimType != EOL) {
-               while ((c = fgetc (psit_file)) != EOF) {
+               while ((c = gbfgetc(psit_file)) != EOF) {
                        if (!isspace(c)) break;
                }
        }
 
-       if (feof(psit_file)) return;
+       if (gbfeof(psit_file)) return;
 
        if (delimType == EOL) {
-               c = fgetc (psit_file);
+               c = gbfgetc(psit_file);
        }
 
        if (c == '#') {
-               if (fgets(buf, sz, psit_file) == NULL) {
+               if (gbfgets(buf, sz, psit_file) == NULL) {
                        *buf = 0;
                        return;
                }
@@ -237,13 +237,13 @@ psit_getToken(FILE *psit_file, char *buf, size_t sz, psit_tokenSep_type delimTyp
        if ((delimType == EOL) || (delimType == ltrimEOL)) {
                *buf = c;
                buf++;
-               fgets(buf, sz-1, psit_file);
+               gbfgets(buf, sz-1, psit_file);
                return;
        }
 
        while (sz--) {
                *buf++ = c;
-               if ((c = fgetc (psit_file)) == EOF) {
+               if ((c = gbfgetc (psit_file)) == EOF) {
                        *buf = 0;
                        return;
                }
@@ -280,7 +280,7 @@ psit_isKnownToken(char *buf)
  * MRCB
  */
 static void
-psit_waypoint_r(FILE *psit_file, waypoint **wpt)
+psit_waypoint_r(gbfile *psit_file, waypoint **wpt)
 {
        int             garmin_icon_num;
 
@@ -326,27 +326,27 @@ psit_waypoint_r(FILE *psit_file, waypoint **wpt)
  * MRCB
  */
 static void
-psit_waypoint_w(FILE *psit_file, const waypoint *wpt)
+psit_waypoint_w(gbfile *psit_file, const waypoint *wpt)
 {
        int     icon;
     const char *ident;
        char *src = 0;  /* BUGBUG Passed to mkshort */
 
-       fprintf(psit_file, "%11.6f,%11.6f,", 
+       gbfprintf(psit_file, "%11.6f,%11.6f,", 
                                                wpt->latitude,
                                                wpt->longitude);
 
        if (wpt->altitude == unknown_alt) 
-               fprintf(psit_file, "********,");
+               gbfprintf(psit_file, "********,");
        else
-               fprintf(psit_file, "%8.2f,",
+               gbfprintf(psit_file, "%8.2f,",
                                                wpt->altitude);
 
        ident = global_opts.synthesize_shortnames ?
                                mkshort(mkshort_handle, src) :
                                wpt->shortname;
 
-       fprintf(psit_file, " %-6s, ", ident);
+       gbfprintf(psit_file, " %-6s, ", ident);
        icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX);
 
        if (get_cache_icon(wpt) && wpt->icon_descr && (strcmp(wpt->icon_descr, "Geocache Found") != 0)) {
@@ -355,9 +355,9 @@ psit_waypoint_w(FILE *psit_file, const waypoint *wpt)
 
        ident = psit_find_desc_from_icon_number(icon);
        if (strlen(ident) == 0)
-               fprintf(psit_file, "%1d\n", icon);
+               gbfprintf(psit_file, "%1d\n", icon);
        else
-               fprintf(psit_file, "%s\n", ident);
+               gbfprintf(psit_file, "%s\n", ident);
 
 }
 
@@ -372,7 +372,7 @@ psit_waypoint_w_wrapper(const waypoint *wpt)
  * MRCB
  */
 static void
-psit_route_r(FILE *psit_file, route_head **rte)
+psit_route_r(gbfile *psit_file, route_head **rte)
 {
        char rtename[256];
        unsigned int rte_num;
@@ -438,7 +438,7 @@ psit_route_r(FILE *psit_file, route_head **rte)
 
                        route_add_wpt(rte_head, thisWaypoint);
 
-                       if (feof(psit_file)) break;
+                       if (gbfeof(psit_file)) break;
 
                        psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), wscomma);
                }
@@ -451,7 +451,7 @@ psit_route_r(FILE *psit_file, route_head **rte)
  * MRCB
  */
 static void
-psit_routehdr_w(FILE *psit_file, const route_head *rte)
+psit_routehdr_w(gbfile *psit_file, const route_head *rte)
 {
        char            hdr[20];
        unsigned int rte_datapoints;
@@ -493,7 +493,7 @@ psit_routehdr_w(FILE *psit_file, const route_head *rte)
                /* check for psitrex comment sign; replace with '$' */
                while ((c = strchr(rname, '#'))) *c = '$';
 
-               fprintf(psit_file, "Route:  %s\n", rname);
+               gbfprintf(psit_file, "Route:  %s\n", rname);
                xfree(rname);
        }
 }
@@ -510,7 +510,7 @@ psit_routehdr_w_wrapper(const route_head *rte)
  * MRCB
  */
 static void
-psit_track_r(FILE *psit_file, route_head **trk)
+psit_track_r(gbfile *psit_file, route_head **trk)
 {
        char tbuf[100];
        char trkname[256];
@@ -600,7 +600,7 @@ psit_track_r(FILE *psit_file, route_head **trk)
                        thisWaypoint->centiseconds = 0;
                        track_add_wpt(track_head, thisWaypoint);
 
-                       if (feof(psit_file)) break;
+                       if (gbfeof(psit_file)) break;
 
                        psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), wscomma);
                }
@@ -613,7 +613,7 @@ psit_track_r(FILE *psit_file, route_head **trk)
  * MRCB
  */
 static void
-psit_trackhdr_w(FILE *psit_file, const route_head *trk)
+psit_trackhdr_w(gbfile *psit_file, const route_head *trk)
 {
        char            hdr[30];
        unsigned int trk_datapoints;
@@ -652,7 +652,7 @@ psit_trackhdr_w(FILE *psit_file, const route_head *trk)
                        /* check for psitrex comment sign; replace with '$' */
                        while ((c = strchr(tname, '#'))) *c = '$';
                        
-                       fprintf (psit_file, "Track:  %s\n", tname);
+                       gbfprintf (psit_file, "Track:  %s\n", tname);
 
                        xfree(tname);
                }
@@ -672,23 +672,23 @@ psit_trackhdr_w_wrapper(const route_head *trk)
  * MRCB
  */
 static void
-psit_trackdatapoint_w(FILE *psit_file, const waypoint *wpt)
+psit_trackdatapoint_w(gbfile *psit_file, const waypoint *wpt)
 {
        time_t  t = wpt->creation_time;
        struct tm *tmTime = gmtime(&t);
 
-       fprintf(psit_file, "%11.6f,%11.6f,", 
+       gbfprintf(psit_file, "%11.6f,%11.6f,", 
                                                wpt->latitude,
                                                wpt->longitude);
 
        if (wpt->altitude == unknown_alt) 
-               fprintf(psit_file, "********, ");
+               gbfprintf(psit_file, "********, ");
        else
-               fprintf(psit_file, "%8.2f, ",
+               gbfprintf(psit_file, "%8.2f, ",
                                                wpt->altitude);
 
        /* Following date time format is fixed and reveals the origin of PsiTrex (i.e. the UK) */
-       fprintf(psit_file, "%02d/%02d/%02d %02d:%02d:%02d,",
+       gbfprintf(psit_file, "%02d/%02d/%02d %02d:%02d:%02d,",
                                                tmTime->tm_mday,
                                                tmTime->tm_mon+1,
                                                tmTime->tm_year % 100,
@@ -696,7 +696,7 @@ psit_trackdatapoint_w(FILE *psit_file, const waypoint *wpt)
                                                tmTime->tm_min,
                                                tmTime->tm_sec);
 
-       fprintf(psit_file," %d\n", psit_track_state);
+       gbfprintf(psit_file," %d\n", psit_track_state);
        psit_track_state = 0;
 }
 
@@ -747,7 +747,7 @@ psit_read(void)
                        }
                        else break;
                }
-       } while (!feof(psit_file_in));
+       } while (!gbfeof(psit_file_in));
 
        return;
 
diff --git a/vcf.c b/vcf.c
index 5ba4608eff66a995bd5c384d9ae66f6cba81814e..05c6a752a918fc770a611a3a27cff6b0dc2608f9 100644 (file)
--- a/vcf.c
+++ b/vcf.c
@@ -23,7 +23,7 @@
 #include "jeeps/gpsmath.h"
 #include <ctype.h>
 
-static FILE *file_out;
+static gbfile *file_out;
 static short_handle mkshort_handle;
 
 static char *vcf_encrypt = NULL;
@@ -40,14 +40,14 @@ arglist_t vcf_args[] = {
 static void
 wr_init(const char *fname)
 {
-       file_out = xfopen(fname, "w", MYNAME);
+       file_out = gbfopen(fname, "w", MYNAME);
        mkshort_handle = mkshort_new_handle();
 }
 
 static void
 wr_deinit(void)
 {
-       fclose(file_out);
+       gbfclose(file_out);
        mkshort_del_handle(&mkshort_handle);
 }
 
@@ -67,7 +67,7 @@ vcf_print_utf(const utf_string *s)
        stripped_html = strip_html(s);
        p = gstrsub(stripped_html, "\n", "\\n");
        p2 = gstrsub(p, "<p>", "\\n");
-       fputs(p2, file_out);
+       gbfputs(p2, file_out);
        xfree(p);
        xfree(p2);
        xfree(stripped_html);
@@ -82,7 +82,7 @@ vcf_print(const char *s)
                return;
 
        p = gstrsub(s, "\n", "\\n");
-       fputs(p, file_out);
+       gbfputs(p, file_out);
        xfree(p);
 }
 
@@ -94,19 +94,19 @@ vcf_disp(const waypoint *wpt)
        lonint = abs((int) wpt->longitude);
        latint = abs((int) wpt->latitude);
 
-       fprintf(file_out, "BEGIN:VCARD\nVERSION:3.0\n");
-       fprintf(file_out, "N:%s;%s;;;\n", wpt->description,wpt->shortname);
-       fprintf(file_out, "ORG:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N',  abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint));
+       gbfprintf(file_out, "BEGIN:VCARD\nVERSION:3.0\n");
+       gbfprintf(file_out, "N:%s;%s;;;\n", wpt->description,wpt->shortname);
+       gbfprintf(file_out, "ORG:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N',  abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint));
 
        if (wpt->url) {
-               fprintf(file_out, "URL:%s\n", wpt->url);
+               gbfprintf(file_out, "URL:%s\n", wpt->url);
        }
 
-       fprintf(file_out, "NOTE:");
+       gbfprintf(file_out, "NOTE:");
        vcf_print_utf(&wpt->gc_data.desc_short);
-       fprintf(file_out, "\\n");
+       gbfprintf(file_out, "\\n");
        vcf_print_utf(&wpt->gc_data.desc_long);
-       fprintf(file_out, "\\n\\nHINT:\\n");
+       gbfprintf(file_out, "\\n\\nHINT:\\n");
        if (vcf_encrypt) {
                char *s = rot13(wpt->gc_data.hint);
                vcf_print(s);
@@ -115,7 +115,7 @@ vcf_disp(const waypoint *wpt)
                vcf_print(wpt->gc_data.hint);
        }
 
-       fprintf(file_out, "\nEND:VCARD\n");
+       gbfprintf(file_out, "\nEND:VCARD\n");
 }
 
 static void